using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MeshSimulation
{
    public partial class SimulationForm : Form
    {
        #region Ctor

        public SimulationForm()
        {
            InitializeComponent();

            InitCombos();
        }

        #endregion

        #region Handlers

        private void m_btnSimStart_Click(object sender, EventArgs e)
        {
            if (!ValidateInput())
                return;
            
            InitManagers();
        }

        private void m_cmbScenarios_SelectionChangeCommitted(object sender, EventArgs e)
        {
            //predefined scenario selection 
            //disables area and stat per AP options
            if (m_cmbScenarios.SelectedItem.ToString().Equals(CommonDefs.SCEN_NONE))
            {
                m_lblAreaSize.Enabled = true;
                m_txtAreaSize.Enabled = true;
                m_lblStatPerAP.Enabled = true;
                m_txtStatPerAP.Enabled = true;
            }
            else
            {
                m_lblAreaSize.Enabled = false;
                m_txtAreaSize.Text = "";
                m_txtAreaSize.Enabled = false;
                m_lblStatPerAP.Enabled = false;
                m_txtStatPerAP.Text = "";
                m_txtStatPerAP.Enabled = false;
            }
        }

        #endregion

        #region Utils

        private void InitManagers()
        {
            NetworkManager networkMan;
            CollisionManager collisionMan;
            SimualtionManager simulationMan;

            //network manager
            if (m_cmbScenarios.SelectedItem.ToString().Equals(CommonDefs.SCEN_NONE))
                networkMan = new NetworkManager(Int64.Parse(m_txtAreaSize.Text), Int64.Parse(m_txtStatPerAP.Text));
            else
                networkMan = new NetworkManager(m_cmbScenarios.SelectedItem);

            //collision manager
            collisionMan = new CollisionManager(Double.Parse(m_txtTransRange.Text),
                Double.Parse(m_txtTransRateAPtoAP.Text), Double.Parse(m_txtTransRateAPtoStat.Text));

            //simulation manager
            simulationMan = new SimualtionManager(networkMan, collisionMan, 
                m_cmbSimMode.SelectedItem, Int64.Parse(m_txtSimDuration.Text));
        }

        private bool ValidateInput()
        {
            //TODO: Validate input

            return true;
        }

        private void InitCombos()
        {
            //scenarios combo
            m_cmbScenarios.Items.Add(CommonDefs.SCEN_NONE);
            m_cmbScenarios.Items.Add(CommonDefs.SCEN_1_AP_3_STAT);
            m_cmbScenarios.Items.Add(CommonDefs.SCEN_2_AP_1_STAT);
            m_cmbScenarios.Items.Add(CommonDefs.SCEN_2_AP_2_STAT);
            m_cmbScenarios.Items.Add(CommonDefs.SCEN_2_AP_3_STAT);
            m_cmbScenarios.Text = CommonDefs.SCEN_NONE;

            //simulator mode combo
            m_cmbSimMode.Items.Add(CommonDefs.MODE_SINGLE);
            m_cmbSimMode.Items.Add(CommonDefs.MODE_DUAL);
            m_cmbSimMode.Text = CommonDefs.MODE_SINGLE;
        }


        #endregion

    }
}